package rmi.bank;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import std.bank.Account;

public class AccountRMIImpl extends UnicastRemoteObject implements Account
{
	Account account;
	double balance;
	String name;

	protected AccountRMIImpl(String name, double balance)
			throws RemoteException
	{
		super();
		this.name = name;
		this.balance = balance;
	}

	public synchronized void deposit(double amount)
	{
		if (amount > 0)
		{
			balance += amount;
		}
	}

	@Override
	public double getBalance()
	{
		return balance;
	}

	@Override
	public String getName()
	{
		return name;
	}

	@Override
	public String toString()
	{
		return "[Account: " + name + ": " + balance + "]";
	}

	@Override
	public synchronized void withdraw(double amount)
	{
		if (amount > 0)
		{
			balance -= amount;
		}
	}
}
